﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Locator.Silverlight.Client.Models.ProductsServiceReference;
using GalaSoft.MvvmLight;

namespace Locator.Silverlight.Client.Models.ViewModels.Elements
{
    public class UserProductViewModel : ViewModelBase
    {
        private readonly UserProduct product;

        public UserProductViewModel(UserProduct product)
        {
            this.product = product;
            this.UsedByUser = product.UsedByUser;
        }

        public string Name
        {
            get { return this.product.Name; }
        }

        public int Id
        {
            get { return this.product.Id; }
        }

        /// <summary>
        /// The <see cref="UsedByUser" /> property's name.
        /// </summary>
        public const string UsedByUserPropertyName = "UsedByUser";

        private bool usedByUser;

        /// <summary>
        /// Gets the UsedByUser property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool UsedByUser
        {
            get { return usedByUser; }

            set
            {
                if (usedByUser == value)
                {
                    return;
                }

                usedByUser = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(UsedByUserPropertyName);
            }
        }
    }
}